/**
 * @description: 积分记录
 *
 * @author mashaohua
 * @date 2018年7月10日 下午10:00:52
 * @version 1.0.0.1
 */


var integralHtmljs = {
//		全局变量
        token : null,
        pageIndex : null,
		init : function(accessToken){
			integralHtmljs.token = accessToken;
			return integralHtmljs;
		},
		 initIntegralRecord : function(pageIndex){
			 integralHtmljs.pageIndex = pageIndex;
			 var url = integralHtmljs.getRootPath() + "/aem/person/getIntegralExchange";
			$.post(
					url,
					{
						"staffToken":integralHtmljs.token,
						"index":integralHtmljs.pageIndex,
			        	"size":10,
					},
					function(data){
						if(data.status == "200"){
							var list = data.data.list;
							var html_ = ''; 
							for(var i=0;i<list.length;i++){
								var dataa = formatDateTimeYMDHMSDAY(list[i].createTime);
								html_ +='<div class="integral-item"><div class="in-tt"><span style="color:black">'+ list[i].clickNickName +'给我减少积分</span>'
								 	  +'</div><div class="in-time">' + dataa +'</div>'
								 	  +'<div class="subtract-code">' + list[i].score +'</div></div>';
							}
							$("#duiIntegral").append(html_);
						}else if(data.status == "300"){
							if(pageIndex == 1){
								var html_ = ''; 
								html_ +='<div><div class="in-tt" style=height:80px;" align="center"><span style="color:black">没有兑换记录哦</span>'
								$("#duiIntegral").append(html_);
							}
							loadValid = false ;
						}else{
							var html_ = ''; 
							html_ +='<div><div style=height:80px;" align="center"><span style="color:black">没有兑换记录哦</span>'
								$("#duiIntegral").append(html_)
						}
					},
					"json"
				);
		},
		
		//获取路劲
	    getRootPath:function(){
		     return $("#basePath").val();
	    },
}




var loadValid = true;
//监听是否滑到底部
window.addEventListener('scroll', throttle(loadData, 500, {leading:false}), false);

//加载更多数据
function loadData(){
	if($(window).scrollTop() + $(window).height() >= $(document).height() && loadValid){
		integralHtmljs.pageIndex++;
		integralHtmljs.initIntegralRecord(integralHtmljs.pageIndex); 
	}
}
//频率控制函数
function throttle(fn,delay,options) {
     var wait=false;
     if (!options) options = {};
     return function(){
         var that = this,args=arguments;
         if(!wait){
             if (!(options.leading === false)){
                 fn.apply(that,args);
             }
             wait=true;
             setTimeout(function () {
                 if (!(options.trailing === false)){
                     fn.apply(that,args);
                 }
                 wait=false;
             },delay);
         }
     }
 }